<!-- 系统设置 -->
<template>
    <view class="sustem-setting">
        <van-cell-group inset border>
            <van-cell title="账号注销">
                <template #title>
                    <view class="custom-title"><text>隐藏自己的在线状态</text><img src="@/assets/image/icon128.png"></view>
                </template>
                <template #right-icon>
                    <van-switch v-model="state.OnlineHide" active-color="#13D449" inactive-color="#dcdee0"
                        @change="switchChange('OnlineHide')" />
                </template>
            </van-cell>
        </van-cell-group>
        <van-cell-group inset border>
            <van-cell title="账号注销">
                <template #title>
                    <view class="custom-title"><text>隐藏自己的距离</text><img src="@/assets/image/icon128.png"></view>
                </template>
                <template #right-icon>
                    <van-switch v-model="state.LocationHide" active-color="#13D449" inactive-color="#dcdee0"
                        @change="switchChange('LocationHide')" />
                </template>
            </van-cell>
        </van-cell-group>
        <van-cell-group inset border>
            <van-cell title="账号注销">
                <template #title>
                    <view class="custom-title"><text>隐藏个人状态</text><img src="@/assets/image/icon128.png"></view>
                </template>
                <template #right-icon>
                    <van-switch v-model="state.StateHide" active-color="#13D449" inactive-color="#dcdee0"
                        @change="switchChange('StateHide')" />
                </template>
            </van-cell>
        </van-cell-group>
        <van-cell-group inset border>
            <van-cell title="账号注销">
                <template #title>
                    <view class="custom-title"><text>屏蔽通信录好友</text><img src="@/assets/image/icon128.png"></view>
                </template>
                <template #right-icon>
                    <van-switch v-model="state.IndexHide" active-color="#13D449" inactive-color="#dcdee0"
                        @change="switchChange('IndexHide')" />
                </template>
            </van-cell>
        </van-cell-group>
        <AuthPup :types="2" ref="AuthPupRef">
            <template #auth>
                <OpenMember curIndex="2" />
            </template>
        </AuthPup>
    </view>
</template>
    
<script setup>
import { reactive, getCurrentInstance, onMounted, ref } from "vue"
import { getAuthorization, setAuthorization } from "@/utils/auth.js"
import { onLoad } from '@dcloudio/uni-app'
import PhotoListItem from "@/components/photoListItem/index.vue"
import { showConfirmDialog } from 'vant';

import {
    UserSettings
} from "@/api/person/index.js"

let { proxy } = getCurrentInstance()

const state = reactive({
    checked: false,
    OnlineHide: false, // 状态
    LocationHide: false, // 距离
    StateHide: false, // 隐藏状态
    IndexHide: false, // 通讯录好友
})

const UserSettingsFn = async () => {
    let { data } = await proxy.$get(UserSettings)
    state.OnlineHide = data.OnlineHide == 0 ? false : true
    state.LocationHide = data.LocationHide == 0 ? false : true
    state.StateHide = data.StateHide == 0 ? false : true
    state.IndexHide = data.IndexHide == 0 ? false : true
}

let AuthPupRef = ref()
const checkVisitor = () => {
    AuthPupRef.value.squareFn()
}

onLoad((options) => {
    UserSettingsFn()
})


const switchChange = (name) => {
    let userInfo = JSON.parse(getAuthorization('userInfo'))
    if (userInfo.VipState == 0) {
        state[name] = !state[name] 
        checkVisitor()
        return
    }
}

</script>
    
<style lang="scss" scoped>
.sustem-setting {
    padding-top: 30rpx;
    min-height: 100vh;
    background: #F7F8F9;
}

.van-cell-group {
    margin-bottom: 30rpx;
}

.dia-log-txt {
    padding: 30rpx
}

.custom-title {
    display: flex;
    align-items: center;
    height: 100%;

    img {
        width: 32rpx;
        margin-left: 10rpx;
    }
}
</style>
    